package day05

const val NAME = "Jimmy's friend"

const val NAMES = "jack,jimmy,jerry"

fun main() {

    //截取Jimmy
    val index = NAME.indexOf("\'")
//    val substring = NAME.substring(0, index)
    //kotlin substring intRange写法
    val substring = NAME.substring(0 until index)
    println(substring)

    //split
//    val data = NAMES.split(",")
//    val s = data[0]
//    val split = NAMES.split("\\,")
    //TODO:使用解构语法
    val (origin,dest, proxy ) = NAMES.split(",")

    println("origin:$origin,dest:$dest,proxy:$proxy")
//    println(split)



    //TODO:replace 字符串替换
    val str = "The people's Republic of China"
    val dataStr = "aeiou"
    var replaceStr = "[$dataStr]"
    val replace = str.replace(Regex(replaceStr)) {
        when (it.value) {
            "a" -> "8"
            "e" -> "9"
            "i" -> "3"
            "o" -> "4"
            "u" -> "5"
            else -> it.value
        }
    }

    println(replace)


}

//private fun String.replace(regex: () -> String) {
//    when(regex){
//        "a" -> "8"
//        "e" -> "9"
//        "i" -> "3"
//        "o" -> "4"
//        "u" -> "5"
//        else-> regex
//     }
//}







